package interview;

import java.util.HashSet;

public class interview_02_01 {
    public ListNode removeDuplicateNodes(ListNode head) {
        if(head==null) return head;
        ListNode p=head;
        ListNode q=head.next;
        HashSet<Integer> set=new HashSet<>();
        set.add(p.val);
        while(q!=null){
            if(set.contains(q.val)){
                p.next=q.next;
                q=p.next;
            }
            else{
                set.add(q.val);
                p=p.next;
                q=q.next;
            }

        }
        return head;
    }
}
